package git.soulbgm.service;

import git.soulbgm.common.websocket.WebSocketServer;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author SoulBGM
 * @version 1.0
 * @date 2019/11/22 13:50
 */
@Service
public class TimingService {

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 想所有连接WebSocket的客户端发送现在时间
     */
    @Scheduled(fixedRate = 1000)
    public void broadcastTime() {
        WebSocketServer.sendInfo("当前时间为:" + sdf.format(new Date()), null);
    }

}
